//package jdf;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.innovatepay.merchsdk.util2.RSA;
//;
//import com.opentech.cloud.server.component.api.sdk.AbstractCallbackHandler4Trade;
//import com.opentech.cloud.server.component.api.sdk.ApiClient;
//import com.opentech.cloud.server.component.api.sdk.ApiClientFactory;
//import com.qian.api.ddj.model.*;
//import com.qian.api.ddj.service.IAliCode2Service;
//import com.qian.api.ddj.service.IAliCodeService;
//import com.qian.api.ddj.service.IBusinessService;
//import com.qian.api.ddj.service.IOrderService;
//import com.qian.api.ddj.util.RSAUtils;
//import com.qian.api.ddj.util.SignUtils;
//import com.qian.ddj.pay.util.AESUtil;
//import com.qian.ddj.pay.util.MD5Utils;
//import com.qian.ddj.pay.util.XmlUtils;
//import com.qian.ddj.pay.util.YufuCipherSupport;
//import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
//import com.yaowk.api.common.BaseException;
//import com.yaowk.api.common.PageReq;
//import com.yaowk.api.utils.HttpUtils;
//import com.yaowk.web.common.adapter.ResponseString;
//import com.yufusoft.payplatform.security.cipher.YufuCipher;
//import com.yufusoft.payplatform.security.vo.ParamPacket;
//import org.apache.commons.codec.digest.DigestUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.util.Base64Utils;
//import org.springframework.util.ObjectUtils;
//import org.springframework.web.bind.annotation.PathVariable;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.math.BigDecimal;
//import java.net.URLDecoder;
//import java.security.KeyFactory;
//import java.security.PublicKey;
//import java.security.spec.X509EncodedKeySpec;
//import java.util.HashMap;
//import java.util.LinkedHashMap;
//import java.util.Map;
//import java.util.TreeMap;
//
//@Controller
//@ResponseString
//@RequestMapping("/notify")
//public class NotifyController {
//
//    private final Logger logger = LoggerFactory.getLogger(NotifyController.class);
//
//    @Autowired
//    private IOrderService orderService;
//    @Autowired
//    private IBusinessService businessService;
//    @Autowired
//    private IAliCodeService aliCodeService;
//    @Autowired
//    private IAliCode2Service aliCode2Service;
//
//
//    @RequestMapping("/notifyToUser/{id}")
//    public void notify2User(@PathVariable Integer id) {
//        Order order = new Order();
//        order.setId(id);
//        orderService.notifyToUser(order);
//    }
//
//
//    @RequestMapping("/shqNotify")
//    public String shqNotify(HttpServletRequest request) {
//        logger.info("shqNotify");
//        String resultCode = request.getParameter("result_code");
//
//        if ("200".equals(resultCode)) {
//            logger.info("resultCode == 200");
//            Map<String, String> map = new TreeMap<>();
//            String dataStr = request.getParameter("data");
//            map.put("result_code", resultCode);
//            map.put("result_message", request.getParameter("result_message"));
//            map.put("data", dataStr);
//            Map<String, Object> data = JSON.parseObject(dataStr, Map.class);
//            String orderNo = data.get("merchant_order_sn").toString();
//            Order order = new Order();
//            order.setOrderNo(orderNo);
//            order = orderService.findOne(order);
//            if (order.getStatus().equals(StatusDict.WAIT_PAY)) {
//                logger.info("StatusDict == WAIT_PAY)");
//                Business business = businessService.findById(order.getBusinessId());
//                String sign = DigestUtils.md5Hex(SignUtils.params(map) + business.getSecretKey()).toUpperCase();
//                if (sign.equals(request.getParameter("sign"))) {
//                    logger.info("sign == true)");
//                    try {
//                        orderService.orderFinish(order);
//                        String receive = orderService.notifyToUser(order);
//                        return receive;
//                    } catch (Exception e) {
//                        e.printStackTrace();
//                        logger.info(e.getMessage());
//                    }
//                }
//            }
//        }
//        return "false";
//    }
//
//    @RequestMapping("/yiaiNotify")
//    public String yiaiNotify(HttpServletRequest request) {
//        String status = request.getParameter("opstate");
//        if ("0".equals(status)) {
//            Map<String, String> map = new LinkedHashMap<>();
//            map.put("orderid", request.getParameter("orderid"));
//            map.put("opstate", status);
//            map.put("ovalue", request.getParameter("ovalue"));
//            Order order = new Order();
//            order.setOrderNo(request.getParameter("orderid"));
//            order = orderService.findOne(order);
//            if (StatusDict.WAIT_PAY.equals(order.getStatus())) {
//                Business business = businessService.findById(order.getBusinessId());
//                String sign = DigestUtils.md5Hex(SignUtils.params(map) + business.getSecretKey()).toLowerCase();
//                if (request.getParameter("sign").equals(sign)) {
//                    logger.info("sign == true)");
//                    try {
//                        order.setUpOrderNo(request.getParameter("sysorderid"));
//                        orderService.orderFinish(order);
//                        String receive = orderService.notifyToUser(order);
//                        if ("SUCCESS".equalsIgnoreCase(receive))
//                            return "0";
//                    } catch (Exception e) {
//                        e.printStackTrace();
//                        logger.info(e.getMessage());
//                    }
//                }
//            }
//        }
//        return "-2";
//    }
//
//    @RequestMapping("/xjwfNotify")
//    public String xjkjwfNotify(HttpServletRequest request) {
//        String status = request.getParameter("status");
//        String pay_number = request.getParameter("pay_number");
//        String orderId = request.getParameter("orderId");
//        String amount = request.getParameter("amount");
//
//        if ("000000".equals(status)) {
//            Map<String, String> map = new LinkedHashMap<>();
//            map.put("pay_number", pay_number);
//            map.put("orderId", orderId);
//            map.put("status", status);
//            map.put("amount", amount);
//            Order order = orderService.findByOrderNo(pay_number);
//            Business business = businessService.findById(order.getBusinessId());
//            String sign = DigestUtils.md5Hex(SignUtils.params(map) + business.getSecretKey()).toLowerCase();
//            if (sign.equals(request.getParameter("sign"))) {
//                try {
//                    if (StatusDict.WAIT_PAY.equals(order.getStatus())) {
//                        order.setUpOrderNo(orderId);
//                        orderService.orderFinish(order);
//                    }
//                    String receive = orderService.notifyToUser(order);
//                    return receive;
//                } catch (Exception e) {
//                    e.printStackTrace();
//                    logger.info(e.getMessage());
//                }
//            }
//        }
//        return "false";
//    }
//
//    @RequestMapping("/syksmNotify")
//    public String syksmNotify(HttpServletRequest request) {
//        String attach = request.getParameter("attach");
//        String data = request.getParameter("data");
//        String hmac = request.getParameter("hmac");
//        StringBuilder sb = new StringBuilder();
//        sb.append("attach=")
//                .append(attach)
//                .append("&data=")
//                .append(data)
//                .append("&key=H357SFF768D786EBB07E1B8D9A4DABC");
//        String sign = DigestUtils.md5Hex(sb.toString()).toUpperCase();
//        if (sign.equals(hmac)) {
//            Map<String, String> dataMap = JSON.parseObject(data, Map.class);
//            String orderNo = dataMap.get("trade_no");
//            Order order = new Order();
//            order.setUpOrderNo(orderNo);
//            order = orderService.findOne(order);
//            try {
//                orderService.orderFinish(order);
//                String receive = orderService.notifyToUser(order);
//                return receive;
//            } catch (Exception e) {
//                e.printStackTrace();
//                logger.info(e.getMessage());
//            }
//        }
//        return "FALSE";
//    }
//
//    @RequestMapping("/smzf1Notify")
//    public String zfbsmNotify(HttpServletRequest req) {
//        String respString = "fail";
//        try {
//            String resString = XmlUtils.parseRequst(req);
//            logger.info("通知内容：" + resString);
//
//            Map<String, String> map = XmlUtils.toMap(resString.getBytes(), "utf-8");
//            map = new TreeMap<>(map);
//            Order order = orderService.findByOrderNo(map.get("out_trade_no"));
//            if (map.containsKey("sign")) {
//                Business business = businessService.findById(order.getBusinessId());
//                if (!SignUtils.verifySign(map, business.getSecretKey())) {
//                    logger.info("验证签名不通过");
//                } else {
//                    if ("0".equals(map.get("status")) && "0".equals(map.get("result_code")) && "0".equals(map.get("pay_result")) && order.getRealAmount().multiply(new BigDecimal(100)).compareTo(new BigDecimal(map.get("total_fee"))) == 0) {
//                        //此处可以在添加相关处理业务，校验通知参数中的商户订单号out_trade_no和金额total_fee是否和商户业务系统的单号和金额是否一致，一致后方可更新数据库表中的记录。
//                        if (order.getStatus().equals(StatusDict.WAIT_PAY)) {
//                            orderService.orderFinish(order);
//                        }
//                        String rec = orderService.notifyToUser(order);
//                        if ("SUCCESS".equals(rec))
//                            respString = "success";
//                    }
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return respString;
//    }
//
//    @RequestMapping("/ghtsmNotify")
//    public String ghtsmNotify(HttpServletRequest request) {
//        String dealCode = request.getParameter("dealCode");
//        if ("10000".equals(dealCode)) {
//            Map<String, String> map = new TreeMap<>();
//            Map<String, String[]> parameterMap = request.getParameterMap();
//            for (String key : parameterMap.keySet()) {
//                String[] value = parameterMap.get(key);
//                if (!ObjectUtils.isEmpty(value)) {
//                    map.put(key, value[0]);
//                }
//            }
//            String sign = map.remove("sign");
//            sign = URLDecoder.decode(sign);
//            String result = SignUtils.params(map);
//            Order order = orderService.findByOrderNo(request.getParameter("orderNo"));
//            Business business = businessService.findById(order.getBusinessId());
//            if (RSA.checkSign(result, sign, business.getBackup1())) {
//                try {
//                    order.setUpOrderNo(request.getParameter("cxOrderNo"));
//                    orderService.orderFinish(order);
//                    String receive = orderService.notifyToUser(order);
//                    return receive;
//                } catch (Exception e) {
//                    e.printStackTrace();
//                    logger.info(e.getMessage());
//                }
//            }
//        }
//        return null;
//    }
//
//    @RequestMapping("/ulineNotify")
//    public String ulineNotify(HttpServletRequest request) {
//        String respString = "fail";
//        try {
//            String resString = XmlUtils.parseRequst(request);
//            logger.info("通知内容：" + resString);
//
//            Map<String, String> map = XmlUtils.toMap(resString.getBytes(), "utf-8");
//            map = new TreeMap<>(map);
//            Order order = orderService.findByOrderNo(map.get("out_trade_no"));
//            if (map.containsKey("sign")) {
//                Business business = businessService.findById(order.getBusinessId());
//                if (!SignUtils.verifySign(map, business.getSecretKey())) {
//                    logger.info("验证签名不通过");
//                } else {
//                    if ("SUCCESS".equals(map.get("return_code")) && "SUCCESS".equals(map.get("result_code"))) {
//                        if (!"TRADE_SUCCESS".equals(map.get("trade_state")) && !"SUCCESS".equals(map.get("trade_state"))) {
//                            return respString;
//                        }
//                        if (order.getStatus().equals(StatusDict.WAIT_PAY)) {
//                            order.setUpOrderNo(map.get("transaction_id"));
//                            orderService.orderFinish(order);
//                        }
//                        String rec = orderService.notifyToUser(order);
//                        if ("SUCCESS".equals(rec))
//                            respString = "success";
//                    }
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return respString;
//    }
//
//    @RequestMapping("/wjxjksmNotify")
//    public String wjxjksmNotify(HttpServletRequest request) {
//        String orderNo = request.getParameter("pay_number");
//        Order order = orderService.findByOrderNo(orderNo);
//        if (!ObjectUtils.isEmpty(order)) {
//            Business business = businessService.findById(order.getBusinessId());
//            Map<String, String> map = new LinkedHashMap<>();
//            map.put("amount", request.getParameter("amount"));
//            map.put("orderId", request.getParameter("orderId"));
//            map.put("pay_number", orderNo);
//            String sign = SignUtils.sign(map, business.getSecretKey());
//            if (sign.equals(request.getParameter("sign"))) {
//                try {
//                    if (order.getStatus().equals(StatusDict.WAIT_PAY)) {
//                        orderService.orderFinish(order);
//                    }
//                    String receive = orderService.notifyToUser(order);
//                    return receive;
//                } catch (Exception e) {
//                    e.printStackTrace();
//                    logger.info(e.getMessage());
//                }
//            }
//        }
//        return null;
//    }
//
//    @RequestMapping("/easyPayNotify")
//    public String easyPayNotify(HttpServletRequest request, final HttpServletResponse response) {
//        logger.info("invoke new notify method.......");
//        final String receive = "SUCCESS";
//        ApiClient apiClient = ApiClientFactory.newClient("https://gw.ak47pay.com/native/", "ZFCK24000JAXS", "2017102821494327000");
//        apiClient.callback4Trade(request, response, new AbstractCallbackHandler4Trade() {
//            @Override
//            public void paySucceed(JSONObject jdata) {
//                Order order = orderService.findByOrderNo(jdata.getString("outTradeNo"));
//                if (StatusDict.WAIT_PAY.equals(order.getStatus()))
//                    orderService.orderFinish(order);
//                String receive = orderService.notifyToUser(order);
//                if (!"SUCCESS".equalsIgnoreCase(receive)) {
//                    throw new BaseException("Fail");
//                }
//            }
//
//            @Override
//            public void payFailed(JSONObject jdata) {
//
//            }
//
//            @Override
//            public void settleSucceed(JSONObject jdata) {
//                this.paySucceed(jdata);
//            }
//        });
//
//        return receive;
//    }
//
//    @RequestMapping("/qdNotify")
//    public String qdNotify(@RequestBody String body) {
//        logger.info(body);
//        JSONObject req = JSON.parseObject(body);
//        if ("900".equals(req.getString("status"))) {
//            Map<String, String> map = JSON.parseObject(req.getString("data"), TreeMap.class);
//
//            String orderNo = map.get("out_trade_no");
//            Order order = orderService.findByOrderNo(orderNo);
//            Business business = businessService.findById(order.getBusinessId());
//            if ("0000".equals(map.get("orderstatus")) && SignUtils.verifySign(map, business.getSecretKey())) {
//                try {
//                    order.setUpOrderNo(map.get("transaction_id"));
//                    if (order.getStatus().equals(StatusDict.WAIT_PAY)) {
//                        orderService.orderFinish(order);
//                    }
//                    String receive = orderService.notifyToUser(order);
//                    if ("SUCCESS".equalsIgnoreCase(receive)) {
//                        return receive;
//                    }
//                } catch (Exception e) {
//                    e.printStackTrace();
//                    logger.info(e.getMessage());
//                }
//            }
//        }
//        return "FAIL";
//    }
//
//
//    @RequestMapping("/yzNotify")
//    public String yzNotify(HttpServletRequest request) {
//        Map<String, String> map = new TreeMap<>();
//        map.put("merchantOutOrderNo", request.getParameter("merchantOutOrderNo"));
//        map.put("merid", request.getParameter("merid"));
//        map.put("msg", request.getParameter("msg"));
//        map.put("noncestr", request.getParameter("noncestr"));
//        map.put("orderNo", request.getParameter("orderNo"));
//        map.put("payResult", request.getParameter("payResult"));
//        map.put("sign", request.getParameter("sign"));
//        if ("1".equals(map.get("payResult"))) {
//
//            String orderNo = map.get("merchantOutOrderNo");
//            Order order = orderService.findByOrderNo(orderNo);
//            Business business = businessService.findById(order.getBusinessId());
//            if (SignUtils.verifySign(map, business.getSecretKey())) {
//                try {
//                    if (order.getStatus().equals(StatusDict.WAIT_PAY)) {
//                        orderService.orderFinish(order);
//                    }
//                    String receive = orderService.notifyToUser(order);
//                    if ("SUCCESS".equalsIgnoreCase(receive)) {
//                        return "success";
//                    }
//                } catch (Exception e) {
//                    e.printStackTrace();
//                    logger.info(e.getMessage());
//                }
//            }
//        }
//        return "fail";
//    }
//
//    @RequestMapping("/DBNotify")
//    public String DBNotify(HttpServletRequest request) {
//        String status = request.getParameter("opstate");
//        if ("0".equals(status)) {
//            Map<String, String> map = new LinkedHashMap<>();
//            map.put("orderid", request.getParameter("orderid"));
//            map.put("opstate", status);
//            map.put("ovalue", request.getParameter("ovalue"));
//            Order order = orderService.findByOrderNo(map.get("orderid"));
//            if (StatusDict.WAIT_PAY.equals(order.getStatus())) {
//                Business business = businessService.findById(order.getBusinessId());
//                String sign = DigestUtils.md5Hex(SignUtils.params(map) + business.getSecretKey());
//                if (request.getParameter("sign").equals(sign)) {
//                    logger.info("sign == true)");
//                    try {
//                        order.setUpOrderNo(request.getParameter("sysorderid"));
//                        orderService.orderFinish(order);
//                        String receive = orderService.notifyToUser(order);
//                        if ("SUCCESS".equalsIgnoreCase(receive))
//                            return "opstate=0";
//                    } catch (Exception e) {
//                        e.printStackTrace();
//                        logger.info(e.getMessage());
//                    }
//                } else {
//                    return "opstate=-2";
//                }
//            }
//        }
//        return "-1";
//    }
//
//    @RequestMapping("/xmkzryNotify")
//    public String xmkzryNotify(@RequestBody String json) {
//        JSONObject jsonObject = JSON.parseObject(json);
//        String orderId = jsonObject.getString("orderId");
//        Order order = orderService.findByOrderNo(orderId);
//        Business business = businessService.findById(order.getBusinessId());
//        byte[] data1 = AESUtil.decrypt(jsonObject.getString("transData").getBytes(), business.getSecretKey().getBytes());
//        StringBuffer sb=new StringBuffer();
//        for (int i=0;i<data1.length;i++){
//            sb.append(data1[i]);
//        }
//        String data = sb.toString();
//        data = new String(Base64Utils.decodeFromString(data));
//        String[] params = data.split("&");
//        Map<String, String> map = new HashMap<>();
//        for (String param : params) {
//            String[] kv = param.split("=");
//            map.put(kv[0], kv[1]);
//        }
//        if ("0".equalsIgnoreCase(map.get("isClearOrCancel"))) {
//            try {
//                orderService.orderFinish(order);
//                String receive = orderService.notifyToUser(order);
//                if ("SUCCESS".equalsIgnoreCase(receive))
//                    return receive;
//            } catch (Exception e) {
//                e.printStackTrace();
//                logger.info(e.getMessage());
//            }
//        }
//        return "fail";
//    }
//
//    @RequestMapping("ryfNotify")
//    public String ryfNotify(HttpServletRequest request) {
//        if ("00".equalsIgnoreCase(request.getParameter("respCode")) && "1".equalsIgnoreCase(request.getParameter("status"))) {
//            String amount = request.getParameter("amount");
//            String orderId = request.getParameter("orderId");
//            String pay_number = request.getParameter("pay_number");
//            Order order = orderService.findByOrderNo(pay_number);
//            Business business = businessService.findById(order.getBusinessId());
//            Map<String, String> map = new TreeMap<>();
//            map.put("amount", amount);
//            map.put("orderId", orderId);
//            map.put("pay_number", pay_number);
//            String sign = SignUtils.sign(map, business.getSecretKey());
//            if (sign.equalsIgnoreCase(request.getParameter("sign"))) {
//                try {
//                    order.setUpOrderNo(request.getParameter("sysorderid"));
//                    orderService.orderFinish(order);
//                    String receive = orderService.notifyToUser(order);
//                    if ("SUCCESS".equalsIgnoreCase(receive))
//                        return "success";
//                } catch (Exception e) {
//                    e.printStackTrace();
//                    logger.info(e.getMessage());
//                }
//            }
//
//        }
//        return new String("fail");
//
//    }
//
//    @RequestMapping("zpayNotify")
//    public String zpay(HttpServletRequest request) {
//        Map<String, String> map = new TreeMap<>();
//        map.put("code", request.getParameter("code"));
//        map.put("app_id", request.getParameter("app_id"));
//        map.put("pay_way", request.getParameter("pay_way"));
//        map.put("out_trade_no", request.getParameter("out_trade_no"));
//        map.put("invoice_no", request.getParameter("invoice_no"));
//        map.put("up_invoice_no", request.getParameter("up_invoice_no"));
//        map.put("money", request.getParameter("money"));
//        map.put("qn", request.getParameter("qn"));
//        if ("0".equalsIgnoreCase(map.get("code"))) {
//            Order order = orderService.findByOrderNo(map.get("out_trade_no"));
//            Business business = businessService.findById(order.getBusinessId());
//            String sign = SignUtils.sign(map, business.getSecretKey()).toUpperCase();
//            if (sign.equalsIgnoreCase(request.getParameter("sign"))) {
//                try {
//                    order.setUpOrderNo(request.getParameter("invoice_no"));
//                    orderService.orderFinish(order);
//                    String receive = orderService.notifyToUser(order);
//                    if ("SUCCESS".equalsIgnoreCase(receive))
//                        return "0";
//                } catch (Exception e) {
//                    e.printStackTrace();
//                    logger.info(e.getMessage());
//                }
//            }
//        }
//        return "";
//    }
//
//    @RequestMapping("/selfZFBNotify")
//    public String selfZFBNotify(HttpServletRequest request) {
//        if ("9902312".equalsIgnoreCase(request.getParameter("key")) && "151261552310206".equalsIgnoreCase(request.getParameter("appid"))) {
//            String remark = request.getParameter("PayMore");
//            BigDecimal amount = new BigDecimal(request.getParameter("PayJe"));
//            String payType = request.getParameter("payType");
//            AliCode aliCode = null;
//            AliCode2 aliCode2 = null;
//            Integer businessId = null;
//            if (StringUtils.isNotBlank(remark)) {
//                businessId = new Integer(remark.split("-")[0]);
//                aliCode = new AliCode();
//                aliCode.setBusinessId(businessId);
//                aliCode.setAmount(amount);
//                aliCode.setRemark(remark);
//                aliCode.setPayType(new Byte(payType));
//                aliCode.setStatus(StatusDict.WAIT_PAY);
//                aliCode = aliCodeService.findOne(aliCode);
//            } else {
//                remark = amount.toString();
//                aliCode2 = new AliCode2();
//                aliCode2.setRemark(remark);
//                aliCode2.setPayType(new Byte(payType));
//                aliCode2.setStatus(StatusDict.WAIT_PAY);
//                aliCode2 = aliCode2Service.findOne(aliCode2);
//            }
//            if (!ObjectUtils.isEmpty(aliCode) || !ObjectUtils.isEmpty(aliCode2)) {
//                Order order = new Order();
//                if (!ObjectUtils.isEmpty(businessId)) {
//                    order.setBusinessId(businessId);
//                }
//                order.setRealAmount(amount);
//                order.setRemark(remark);
//                order.setStatus(StatusDict.WAIT_PAY);
//                PageReq pageReq = new PageReq();
//                pageReq.setPageSize(1);
//                pageReq.setPageNumber(1);
//                order = orderService.findAll(order, pageReq).getList().get(0);
//                if (!ObjectUtils.isEmpty(order)) {
//                    order.setUpOrderNo(request.getParameter("PayNO"));
//                    orderService.orderFinish(order);
//                    if (!ObjectUtils.isEmpty(aliCode)) {
//                        aliCode.setStatus(StatusDict.NORMAL);
//                        aliCodeService.save(aliCode);
//                    } else if (!ObjectUtils.isEmpty(aliCode2)) {
//                        aliCode2.setStatus(StatusDict.NORMAL);
//                        aliCode2Service.save(aliCode2);
//                    }
//                    try {
//                        String rec = orderService.notifyToUser(order);
//                        logger.info("{} receive {}", order.getOutOrderNo(), rec);
//                    } catch (Exception e) {
//                        e.printStackTrace();
//                        logger.info(e.getMessage());
//                    }
//                    return "Success";
//                }
//            }
//        }
//        return "Fail";
//    }
//
//    @RequestMapping("pay01Notify")
//    public String pay01Notify(@RequestBody String receive) {
//        logger.info(receive);
//        Map map = JSON.parseObject(receive, Map.class);
//        Map<String, String> data = new TreeMap<>(map);
//        String sign = data.remove("sign");
//        String orderNo = data.get("orderNo");
//        Order order = orderService.findByOrderNo(orderNo);
//        Business business = businessService.findById(order.getBusinessId());
//        if ("1".equalsIgnoreCase(data.get("orderStatus")) && DigestUtils.md5Hex(SignUtils.params(data) + business.getSecretKey()).equalsIgnoreCase(sign)) {
//            try {
//                orderService.orderFinish(order);
//                receive = orderService.notifyToUser(order);
//                if ("SUCCESS".equalsIgnoreCase(receive))
//                    return "success";
//            } catch (Exception e) {
//                e.printStackTrace();
//                logger.info(e.getMessage());
//            }
//        }
//
//        return "fail";
//    }
//
//    @RequestMapping("nsNotify")
//    public String nsNotify(HttpServletRequest request) {
//        Map<String, String> data = new TreeMap<>();
//        data.put("amount", request.getParameter("amount"));
//        data.put("orderId", request.getParameter("orderId"));
//        data.put("pay_number", request.getParameter("pay_number"));
//        data.put("sign", request.getParameter("sign"));
//        String orderNo = request.getParameter("pay_number");
//        Order order = orderService.findByOrderNo(orderNo);
//        Business business = businessService.findById(order.getBusinessId());
//        if ("SUCCESS".equalsIgnoreCase(request.getParameter("respCode")) && "SUCCESS".equalsIgnoreCase(request.getParameter("trade_state")) && SignUtils.verifySign(data, business.getSecretKey())) {
//            try {
//                orderService.orderFinish(order);
//                String receive = orderService.notifyToUser(order);
//                if ("SUCCESS".equalsIgnoreCase(receive))
//                    return receive;
//            } catch (Exception e) {
//                e.printStackTrace();
//                logger.info(e.getMessage());
//            }
//        }
//
//        return "FAIL";
//    }
//
//    @RequestMapping("/pay02Notify")
//    public String pay02Notify(HttpServletRequest request) {
//        String orderNo = request.getParameter("orderid");
//        String returncode = request.getParameter("returncode");
//        if ("00".equalsIgnoreCase(returncode)) {
//            Map<String, String> map = new TreeMap<>();
//            map.put("memberid", request.getParameter("memberid"));
//            map.put("orderid", orderNo);
//            map.put("amount", request.getParameter("amount"));
//            map.put("transaction_id", request.getParameter("transaction_id"));
//            map.put("datetime", request.getParameter("datetime"));
//            map.put("returncode", request.getParameter("returncode"));
//            map.put("sign", request.getParameter("sign"));
//            Order order = orderService.findByOrderNo(orderNo);
//            Business business = businessService.findById(order.getBusinessId());
//            if (SignUtils.verifySign(map, business.getSecretKey())) {
//                order.setUpOrderNo(map.get("transaction_id"));
//                try {
//                    orderService.orderFinish(order);
//                    String receive = orderService.notifyToUser(order);
//                    if ("SUCCESS".equalsIgnoreCase(receive))
//                        return "OK";
//                } catch (Exception e) {
//                    e.printStackTrace();
//                    logger.info(e.getMessage());
//                }
//            }
//        }
//        return "";
//    }
//
//    @RequestMapping("/pay03Notify")
//    public String pay03Notify(@RequestBody String jsonStr) {
//        Map<String, String> map = JSON.parseObject(jsonStr, Map.class);
//        map = new TreeMap(map);
//        String orderNo = map.get("ORDER_NO");
//        if ("1".equalsIgnoreCase(map.get("ORD_STS"))) {
//            Order order = orderService.findByOrderNo(orderNo);
//            Business business = businessService.findById(order.getBusinessId());
//            String sign = map.remove("SIGN_DAT");
//            if (DigestUtils.md5Hex(SignUtils.params(map) + "&KEY=" + business.getSecretKey()).equalsIgnoreCase(sign)) {
//                try {
//                    orderService.orderFinish(order);
//                    String receive = orderService.notifyToUser(order);
//                    if ("SUCCESS".equalsIgnoreCase(receive))
//                        return receive;
//                } catch (Exception e) {
//                    e.printStackTrace();
//                    logger.info(e.getMessage());
//                }
//            }
//        }
//        return "fail";
//    }
//
//    @RequestMapping("/HYMTNotify")
//    public String HYMTNotify(@RequestBody String receive) {
//        System.out.println(receive);
//        JSONObject jsonObject = JSON.parseObject(receive);
//        int status = jsonObject.getIntValue("status");
//        if (2 == status) {
//            String orderId = jsonObject.getString("orderid");
//            Order order = orderService.findByOrderNo(orderId);
//            Business business = businessService.findById(order.getBusinessId());
//            Map<String, String> map = new TreeMap<>();
//            map.put("amount", jsonObject.getString("amount"));
//            map.put("appid", jsonObject.getString("appid"));
//            map.put("orderid", orderId);
//            map.put("status", String.valueOf(status));
//            map.put("sign", jsonObject.getString("signature"));
//            if (SignUtils.verifySign(map, business.getSecretKey())) {
//                try {
//                    orderService.orderFinish(order);
//                    receive = orderService.notifyToUser(order);
//                    if ("SUCCESS".equalsIgnoreCase(receive))
//                        return receive;
//                } catch (Exception e) {
//                    e.printStackTrace();
//                    logger.info(e.getMessage());
//                }
//            }
//        }
//        return "FAIL";
//    }
//
//    @RequestMapping("/HJNotify")
//    public String HJNotify(HttpServletRequest request) {
//        String orderNo = request.getParameter("pay_number");
//        if ("0".equalsIgnoreCase(request.getParameter("respCode"))) {
//            Order order = orderService.findByOrderNo(orderNo);
//            Business business = businessService.findById(order.getBusinessId());
//            Map<String, String> map = new TreeMap<>();
//            map.put("orderId", request.getParameter("orderId"));
//            map.put("amount", request.getParameter("amount"));
//            map.put("pay_number",orderNo);
//            map.put("sign", request.getParameter("sign"));
//            if (SignUtils.verifySign(map, business.getSecretKey())) {
//                try {
//                    orderService.orderFinish(order);
//                    String receive = orderService.notifyToUser(order);
//                    if ("SUCCESS".equalsIgnoreCase(receive))
//                        return receive;
//                } catch (Exception e) {
//                    e.printStackTrace();
//                    logger.info(e.getMessage());
//                }
//            }
//        }
//
//        return "FAIL";
//    }
//    @RequestMapping("/QFQNotify")
//    public String QFQNotify(HttpServletRequest request) throws Exception {
////        String signMsg = request.getParameter("signMsg");
////        String outOrderId = request.getParameter("outOrderId");
////        String payType = request.getParameter("payType");
//        String inOrderId = request.getParameter("inOrderId");
////        String tradeStatus = request.getParameter("tradeStatus");
//        Order order = new Order();
//        order.setUpOrderNo(inOrderId);
//        order = orderService.findOne(order);
//        Business business = businessService.findById(order.getBusinessId());
////        com.qian.api.ddj.util.RSA.checkSign()
//        // 获取所有回调参数
//        Map<String, String[]> paramMap = new HashMap<String, String[]>();
//        paramMap.putAll(request.getParameterMap());
//
//        // 移除signType和signMsg，这两个参数不参与签名
//        String[] signType = paramMap.remove("signType");
//        String[] signData = paramMap.remove("signMsg");
//        System.out.println("七分钱签名："+signData[0]);
//
//        // 校验签名方法和签名是否为空
//        if(!SignUtils.checkSignData(signType, signData)){
//            // 签名为空，直接返回七分钱“failure”
//            return "failure";
//        }
//
//        // 对移除signType和signMsg后的剩余参数进行排序、组装，获得待签名字符串。
//        String signMsg = SignUtils.dealSignParam(paramMap);
//        System.out.println("签名字符串："+signMsg);
//
//        byte[] data = signMsg.getBytes("UTF-8");
//
//        // 七分钱使用RSA方式进行签名
//        if ("RSA".equals(signType[0])) {
//
//            // 获取七分钱公钥sysPublicKey
//            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
//            byte[] sevenPubKeyBytes = Base64.decode(business.getBackup1());
//            X509EncodedKeySpec sevenPubKeySpec = new X509EncodedKeySpec(sevenPubKeyBytes);
//            PublicKey sevenPubKey = keyFactory.generatePublic(sevenPubKeySpec);
//            // 校验签名
//            boolean result = RSAUtils.verify(data, sevenPubKey, signData[0]);
//
//            if (!result) {
//                System.out.println("签名验证不通过");
//                return "failure";
//            }
//            else{
//                System.out.println("签名验证通过");
//
//                // 校验通过后，处理订单支付结果返回信息
//                try {
//                    orderService.orderFinish(order);
//                    String receive = orderService.notifyToUser(order);
//                    if ("SUCCESS".equalsIgnoreCase(receive))
//                        return "success";
//                } catch (Exception e) {
//                    e.printStackTrace();
//                    logger.info(e.getMessage());
//                }
//
//                // 商户后台通知处理完成之后必须返回给七分钱“success”
//
//            }
//        } else {
//            System.out.println("签名方式错误，当前版本只支持RSA签名");
//        }
//        return "failure";
//    }
//
////    @RequestMapping("/YLEWMNotify")
////    public String ylewmNofity(HttpServletRequest request){
////
////    }
//
//    @RequestMapping("/YLSMNotify")
//    public String ylsmNotify(@RequestBody String receive){
//        System.out.println("接收到的参数："+receive);
//        JSONObject jsonObject = JSONObject.parseObject(receive);
//        String mch_id = jsonObject.getString("MERC_ID");
//        String ord_sts = jsonObject.getString("ORD_STS");
//        String out_trade_no = jsonObject.getString("ORDER_NO");
//        System.out.println("订单编号："+out_trade_no);
//        Order order=  new Order();
//        order.setOrderNo(out_trade_no);
//        order = orderService.findOne(order);
//        Business business = businessService.findById(order.getBusinessId());
//        if (!MD5Utils.checkSign(jsonObject, business.getSecretKey())) {
//            System.out.println("数据签名验证错误");
//            return "fail";
//        }
//        System.out.println("数据签名验证成功");
//        System.out.println("返回外部订单号："+out_trade_no);
//        System.out.println("返回商户号："+mch_id);
//        System.out.println("返回交易状态："+ord_sts);
//        if ("1".equals(jsonObject.getString("ORD_STS"))){
//            try {
//                orderService.orderFinish(order);
//                receive = orderService.notifyToUser(order);
//                if ("SUCCESS".equalsIgnoreCase(receive))
//                    return "SUCCESS";
//            } catch (Exception e) {
//                e.printStackTrace();
//                logger.info(e.getMessage());
//            }
//        }
//        return "fail";
//    }
//
//    @RequestMapping("/zfbsmNotify")
//    public String zfbsmNotify1(HttpServletRequest request){
//        Map map = new TreeMap<>();
//        map.putAll(request.getParameterMap());
//        map.remove("merParam");
//        String sign = String.valueOf(map.get("signData"));
//        map.remove("signData");
//        Order order = new Order();
//        order.setOrderNo((String) map.get("prdOrdNo"));
//        order = orderService.findOne(order);
//        Business business = businessService.findById(order.getBusinessId());
//        if (sign.equals(business.getSecretKey())){
//            if ("01".equals(map.get("orderStatus"))){
//                try {
//                    orderService.orderFinish(order);
//                    String receive = orderService.notifyToUser(order);
//                    if ("SUCCESS".equalsIgnoreCase(receive))
//                        return "SUCCESS";
//                } catch (Exception e) {
//                    e.printStackTrace();
//                    logger.info(e.getMessage());
//                }
//            }
//        }
//        return "fail";
//    }
//
//    @RequestMapping("/yufuNotify")
//    public String yufuNotify(HttpServletRequest req){
//        YufuCipher cipher;
//        Map map = new HashMap();
//        Map<String, String> synchNotifyParams =null;
//        map.putAll(req.getParameterMap());
//        try{
//            cipher = YufuCipherSupport.getCipherInstance();
//            synchNotifyParams = cipher.unPack(new ParamPacket(req.getParameter("data"), req.getParameter("enc"), req.getParameter("sign")));
//        }catch (Exception e){
//            e.printStackTrace();
//        }
//        Order order = new Order();
//        order.setOrderNo(synchNotifyParams.get("merchantOrderId"));
//        order = orderService.findOne(order);
//        if ("01".equals(synchNotifyParams.get("transStatus"))){
//            try {
//                order.setUpOrderNo(synchNotifyParams.get("bpSerialNum"));
//                orderService.orderFinish(order);
//                String receive = orderService.notifyToUser(order);
//                if ("SUCCESS".equalsIgnoreCase(receive))
//                    return "SUCCESS";
//            } catch (Exception e) {
//                e.printStackTrace();
//                logger.info(e.getMessage());
//            }
//        }
//        return "success";
//    }
//}
//
//
//
